<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<>
    <script type="text/javascript" src="js1/jquery-1.11.1.js"></script>
    <input type="checkbox">香蕉
    <input type="checkbox">苹果
    <input type="checkbox">橘子
    <input type="checkbox">全选/全不选
<script type="text/javascript">
    var a= $(":checkbox:last").index()
    console.log(a)
        $(":checkbox:not(:last)").click(function () {
            if ($(this).prop("checked")==false){
                $(":checkbox:last").prop("checked",false);
            }else{
               // var c=0;
                for (var s=0;s<a-1;s++){
                    if ($(":checkbox:eq("+ s +")").prop("checked")){
                        c++;
                       console.log(c)
                    }
                    //console.log(s)
                }
                if (c==a-1){
                    $(":checkbox:last").prop("checked",true);
                }
            }
    })
</script>
</body>
</html>